@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">用户管理</div>
                <div class="panel-body">
                    @if (count($errors) > 0)
                        <div class="alert alert-danger">
                            {!! implode('<br>', $errors->all()) !!}
                        </div>
                    @endif

                    <table class="table">
                        <thead>
                        <tr>
                            <th>用户名</th>
                            <th>权限</th>
                            <th>电子邮箱</th>
                            <th>创建日期</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        
                        <tbody>

                                @foreach ($users as $user)
                                <tr>
                                    <td>{{ $user->name }}</td>
                                    <td>{{ $user->groupm }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>{{ $user->created_at }}</td>
                                    <td>
                                    @if ( $auth->groupm == "administrator")
                                        <a href="{{ url('admin/user/'.$user->id.'/edit') }}" class="btn btn-success">编辑</a>
                                        <form action="{{ url('admin/user/'.$user->id) }}" method="POST" style="display: inline;">
                                            {{ method_field('DELETE') }}
                                            {{ csrf_field() }}
                                            <button type="submit" class="btn btn-danger">删除</button>
                                        </form>
                                    @else
                                        <a href="" class="btn btn-success" disabled>编辑</a>
                                        <form action="" method="POST" style="display: inline;">
                                            <button type="submit" class="btn btn-danger" disabled>删除</button>
                                        </form>
                                    @endif
                                    </td>
                                </tr>
                                @endforeach

                            </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection